/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package DAO;
import DTO.CConfig;
import DTO.CFields;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author quangphuc
 */
public class CConfigDAO extends IData<CConfig>{

    @Override
    public CConfig add(CConfig item) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void saveBatch() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int addrows(List<CConfig> list, SubConfig config) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public CConfig Find(CConfig item, List<CConfig> list) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    protected Object OnSubmit(CConfig item, int t, SubConfig config) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Object insertOnSubmit(CConfig item, SubConfig config) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Object updateOnSubmint(CConfig item, SubConfig config) {
        Object result = 0;
        String mysql ="update " + CFields.tb_config + " set value=? where id = ?";
        try {
            PreparedStatement cs = config.connec.prepareStatement(mysql);
            cs.setString(1, item.getValue());
            cs.setLong(2, item.getId());
            result = cs.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(CConfigDAO.class.getName()).log(Level.SEVERE, null, ex);
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }        
        return result;
    }

    @Override
    public Object deleteOnSubmint(CConfig item, SubConfig config) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    protected CConfig getItem(ResultSet rs) {
        CConfig item = new CConfig();
        try {
            item.setId(rs.getLong(CFields.id));
            item.setMoTa(rs.getString(CFields.mo_ta));
            item.setName(rs.getString(CFields.name));
            item.setValue(rs.getString(CFields.value));
            item.setType(rs.getString(CFields.type));
        } catch (SQLException ex) {
            Logger.getLogger(CConfigDAO.class.getName()).log(Level.SEVERE, null, ex);
             throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
       
        return item;
    }

    @Override
    public List<CConfig> getAll(SubConfig config) {
        String mysql =" select * from " + CFields.tb_config + " " + this.sWhere;
        return this.getAll(mysql, config);
    }

    @Override
    protected void add(CConfig item, int t) {
        try {
            ps.setString(1, item.getValue());
            ps.setString(2, item.getType());
            ps.setLong(3, item.getId());
            ps.addBatch();
        } catch (SQLException ex) {
            Logger.getLogger(CConfigDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void updates(List<CConfig> list,SubConfig config){
        this.query = "update " + CFields.tb_config + " set value =?,type=?  where " + CFields.id + "=?" ;
        try {
            this.updateRows(list, config);
        } catch (SQLException ex) {
            Logger.getLogger(CConfigDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
 
}
